﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
    public class ApplicationDbContext : DbContext
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
        {
        }

        // 数据字典表
        public DbSet<SysDictType> SysDictTypes { get; set; }
        public DbSet<SysDictData> SysDictDatas { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            // 配置表名和架构
            modelBuilder.Entity<SysDictType>().ToTable("sys_dict_type");
            modelBuilder.Entity<SysDictData>().ToTable("sys_dict_data");

            // 配置关系
            modelBuilder.Entity<SysDictData>()
                .HasOne(d => d.DictTypeInfo)
                .WithMany(t => t.DictDatas)
                .HasForeignKey(d => d.DictType)
                .HasPrincipalKey(t => t.DictType);
        }
    }
}
